package com.huawei.hms.framework.network.grs.local;

import android.text.TextUtils;
import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.network.grs.GrsBaseInfo;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class d {
    public static final Set<String> a = Collections.unmodifiableSet(new HashSet<String>(16) {
    });
    private static final String b = d.class.getSimpleName();

    public static String a(String str, GrsBaseInfo grsBaseInfo) {
        if (TextUtils.isEmpty(str)) {
            Logger.w(b, "routeBy must be not empty string or null.");
            return null;
        } else if (!"no_route".equals(str) && !"unconditional".equals(str)) {
            return b(str, grsBaseInfo);
        } else {
            Logger.v(b, "routeBy equals NO_ROUTE_POLICY");
            return "no_route_country";
        }
    }

    private static String b(String str, GrsBaseInfo grsBaseInfo) {
        String str2 = "";
        Object serCountry = grsBaseInfo.getSerCountry();
        CharSequence regCountry = grsBaseInfo.getRegCountry();
        CharSequence issueCountry = grsBaseInfo.getIssueCountry();
        for (String str3 : str.split(">")) {
            if (a.contains(str3.trim())) {
                if ("ser_country".equals(str3.trim()) && !TextUtils.isEmpty(serCountry)) {
                    return serCountry;
                }
                if ("reg_country".equals(str3.trim()) && !TextUtils.isEmpty(regCountry)) {
                    return regCountry;
                }
                if ("issue_country".equals(str3.trim()) && !TextUtils.isEmpty(issueCountry)) {
                    return issueCountry;
                }
            }
        }
        return str2;
    }
}
